package base.components.WarmC
{
	import flash.events.Event;
	import flash.events.MouseEvent;
	
	import mx.controls.ComboBox;
	import mx.core.ClassFactory;
	import mx.events.FlexEvent;
	import mx.events.ListEvent;

	public class MyComboBox extends ComboBox{
		private var mouseOut:Boolean=true;
		private var promptText:String="";
		
		public var forUseItems:Array;
		
		public function MyComboBox(){
			super();
			this.addEventListener(FlexEvent.CREATION_COMPLETE,onCreateCompleteHandle);
			this.itemRenderer=new ClassFactory(CheckBoxItemRenderer);
		}
		
		private function onCreateCompleteHandle(event:FlexEvent):void
		{
			dropdown.allowMultipleSelection=true;
			close();
		}
		
		private function initListener():void
		{
			if(!dropdown.hasEventListener(MouseEvent.ROLL_OVER))
				dropdown.addEventListener(MouseEvent.ROLL_OVER,onRollOverHandle);
			if(!dropdown.hasEventListener(MouseEvent.ROLL_OUT))
				dropdown.addEventListener(MouseEvent.ROLL_OUT,onRollOutHandle);
		}
		
		private function onRollOverHandle(event:MouseEvent):void
		{
			mouseOut=false;
		trace("roll over  mouseOut=false", "selectedIndex:" + selectedIndex);
		}
		private var changeEvent:ListEvent;
		
		private function onRollOutHandle(event:MouseEvent):void
		{
	trace("rollOut mouseOut=true", selectedItems.toString());
			mouseOut=true;
			if(selectedItems.length>0)
			{
				this.forUseItems = selectedItems;
				close();
				changeEvent= new ListEvent( ListEvent.CHANGE )
				dispatchEvent( changeEvent);
			}
		}
		
		public function set selectedItems(value:Array):void
		{
			for (var i:int = 0; i < value.length; i++) 
			{
				trace(dropdown, "selectedItems..........", value[i].name);
			}
			
			if (dropdown)
			{
				dropdown.selectedItems=value;
			}
			else
			{
				callLater( function(value:Array):void{selectedItems = value}, [value] );
			}	
		}

		[Bindable("change")]
		public function get selectedItems():Array
		{
			return dropdown?dropdown.selectedItems:[];
		}
		
		public function set selectedIndices(value:Array):void{
			if (dropdown)
				dropdown.selectedIndices=value;
		}

		[Bindable("change")]
		public function get selectedIndices():Array{
			return dropdown?dropdown.selectedIndices:[];
		}
		
		override public function close(trigger:Event=null):void{
			initListener();
			if (mouseOut)
				super.close(trigger);
			if(promptText)
				this.textInput.text=promptText;
	trace("text: ", textInput.text, "----------------------", "selectedIndex:" + selectedIndex);
		}
		override public function set prompt(value:String):void{
			promptText=value;
			trace("propmt: ", promptText)
		}
	}
}